<template>
	<view class="flex justify-between align-center text-center" style="line-height:1;">
		<view class="circleBtn col1" @click="reduceNum"><text class="base-font-40">-</text></view>
		<view><input  name="input" v-model="value" style="width:54rpx;line-height: 40rpx;pointer-events: none;"></input></view>
		<view class="circleBtn col2"  @click="addNum"><text class="base-font-40">+</text></view>
	</view>
</template>

<script>
	export default{
		
		data(){
			return{
				value:1,
			}
		},
		props:{
			params: {
				type: String,
				default: ''
			},
			num: {
				type: [Number, String],
				default: 1
			},
			min: {
				type: Number,
				default: 0
			},
			max: {
				type: Number,
				default: 100
			},
			step: {
				type: Number,
				default: 1
			},
			disabled: {
				type: Boolean,
				default: false
			}
		},
		watch: {
			num(val) {
				console.log("foodNum==="+val);
				this.value =val;
			}
		},
		mounted() {
			this.value=this.num;
		},
		methods:{
			addNum(data){
				if (this.disabled) {
					return;
				}
				this.value += this.step;
				if (this.value < this.min) {
					this.value=this.min;
				}
				
				if(this.value > this.max){
					this.value = this.max
				}
				this.changeValue();
			},
			reduceNum(){
				if (this.disabled) {
					return;
				}
				this.value -= this.step;
				if (this.value < this.min) {
					this.value=this.min;
				}
				
				if(this.value > this.max){
					this.value = this.max
				}
				this.changeValue();
			},
			changeValue(){
				this.$emit('change',this.value,this.params);
			}
		}
	}
</script>

<style>
	.circleBtn{width:40rpx;height:40rpx;border-radius:50%;border:2rpx solid #000;line-height:40rpx;}
	.col1{border:2rpx solid #000;}
	.col3{background:#ebedf0;border-color:#ebedf0;}
	.col2{background:#FA3F40;border-color:#FA3F40;color: white;}
</style>